package task03.code0301;

public class MaxSonStr {
    public static void main(String[] args) {
        String maxSonStr = getMaxSonStr("asdafghjka", "aaasdfg");
        if ("".equals(maxSonStr)) {
            System.out.println("没有最大子串");
        } else {
            System.out.println("最大子串：" + maxSonStr);
        }

    }

    static String getMaxSonStr(String s1, String s2) {
        String maxStr = s1.length() > s2.length() ? s1 : s2;
        String minStr = s1.length() > s2.length() ? s2 : s1;
        String maxSonStr = "";
        String sonStr = "";
        if (maxStr.contains(minStr))
            return minStr;
        outer: for (int i = 1; i < minStr.length(); i++) {
            for (int j = 0; j <= i; j++) {
                sonStr = minStr.substring(j, minStr.length() - i + j);
                if (maxStr.contains(sonStr)) {
                    maxSonStr = sonStr;
                    break outer;
                }

            }
        }
        return maxSonStr;
    }
}
